function [ C ] = getnews( code, num, Sec )
%   C = getnews(code,num,Sec)
%   example:getnews('000001',3,'sz') 获取000001的最新3条新闻
%           getnews('000001','today')获取000001的今日新闻
%           getnews('600000')        获取600000的第一页全部新闻
%

if nargin<3
    if strmatch('600',code);
        Sec = 'sh';
    end
    if strmatch('000',code);
        Sec = 'sz';%默认读取深交所
    end
end

url = strcat('http://cj.gw.com.cn/news/stock/',Sec,code,...
                                           '/pageNewsCompanyMore_1.shtml');
text = urlread(url,'Charset','UTF-8');

head = max(findstr('公司新闻',text));
foot = findstr('脚部',text);
news = text(head:foot);

%% 提取新闻数据
pre = findstr('"more">',news);
mid = findstr('<span>',news);
lst = findstr('</span>',news);
lst = lst(2:end);
C = [];

for i =1:length(pre)
    C = strcat(C,10,news(pre(i)+6:mid(i)-5),'[',news(mid(i)+6:lst(i)-1),']');
    time(i,:) = news(mid(i)+6:lst(i)-1);
    time(i,:) = strrep(time(i,:),'日',' ');
    time(i,:) = strrep(time(i,:),'月','/');
end

%% 展示num数量的新闻

if nargin<2
    return;
end

if nargin>=2
        enter = findstr(10,C);
    if strcmp(num,'now')|strcmp(num,'today')
        C = C(1:enter(strmatch(datestr(now,6),time)+1));
    else if strcmp(class(num),'double')
        C = C(1:enter(num+1));
        end
    end
end

if isempty(C)
    C = '   无新闻';
end

end

